Caffe 使用总结

Caffe 安装常见问题

编译错误

After ‘make all’, you may face two errors. Here are the solutions:

Error One:

./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: No such file or directory
compilation terminated.

Solutions:

1
2
3
4
5
6
7
wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make
sudo make install

Error Two:

./include/caffe/data_layers.hpp:11:18: fatal error: lmdb.h: No such file or directory
Solution:

1
2
3
4
git clone git://gitorious.org/mdb/mdb.git
cd mdb/libraries/liblmdb
make
sudo make install

Python 接口调用错误

After the installation of caffe, you could build the python interfance for it:

1
2
3
4
5
6
sudo ln -s /usr/include/python2.7/ /usr/local/include/python2.7
sudo ln -s /usr/local/lib/python2.7/dist-packages/numpy-1.8.1-py2.7-linux-x86_64.egg/numpy/core/include/numpy /usr/local/include/python2.7/numpy
make pycaffe
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc
source ~/.bashrc
sudo easy_install pillow

If when you run ‘make pycaffe’, you see this error

Error One:

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe2 in position 54: ordinal not in range(128)
you could fix it by running:

1
sudo apt-get install libevent-dev python-dev

That should be the end of the installation. You can test that it runs with:

1
python python/classify.py --print_results examples/images/cat.jpg foo

The expected output is:

1
[('kit fox', '0.27327'), ('red fox', '0.20591'), ('wood rabbit', '0.12281'), ('Egyptian

Error Two:

Pycaffe not working: No module named google.protobuf.internal

1
2
cd ~/anaconda2/bin/
pip install protobuf

安装配置nVidia cuDNN 加速Caffe模型运算

a. 安装cuDNN
该改版本caffe-master默认支持cudnn-6.5-linux-x64-v2,使用cudnn-6.5-linux-R1会报错,安装前请去先官网下载最新的cuDNN

1
2
3
4
$ sudo cp cudnn.h /usr/local/include
$ sudo cp libcudnn.so /usr/local/lib
$ sudo cp libcudnn.so.6.5 /usr/local/lib
$ sudo cp libcudnn.so.6.5.48 /usr/local/lib

b. 链接cuDNN的库文件

1
2
3
$ sudo ln -sf /usr/local/lib/libcudnn.so.6.5.48 /usr/local/lib/libcudnn.so.6.5
$ sudo ln -sf /usr/local/lib/libcudnn.so.6.5 /usr/local/lib/libcudnn.so
$ sudo ldconfig -v

opencv

Unsupported gpu architecture ‘compute_11’

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
cmake需要指定GPU架构3 :-D CUDA_GENERATION=Kepler,否则报错:Unsupported gpu architecture ‘compute_11’
生成lib/libopencv_highgui.so.2.4.9找不到png_set_longjmp_fn,可以这样解决:
google之后发现这个函数定义在libpng中

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看libopencv_highgui.so.2.4.9引用了哪个libpng
$ ldd lib/libopencv_highgui.so.2.4.9 | grep libpng
# 查看该lipng中是否定义了png_set_longjmp_fn,注意根据自己的环境替换掉/usr/lib64/libpng12.so.0.49.0
$ readelf -s /usr/lib64/libpng12.so.0.49.0 | grep png_set_longjmp_fn
# 没有任何输出,说明没有定义,则需要安装更新的版本
$ wget http://github.com/glennrp/libpng-releases/raw/master/libpng-1.5.23.tar.xz
$ tar -xvf libpng-1.5.23.tar.xz
$ cd libpng-1.5.23
$ make install
# 安装后发现仍然找不到,这是因为链接时查找路径的问题4:
$ cd /usr/local/lib
$ cp -d libpng15.a libpng15.la libpng15.so* libpng.a libpng.* /usr/lib64

绘制模型的结构

To install this package with conda run:

1
conda install -c rmg pydot=1.2.2

caffe python Exception: “dot” not found in path

Installed GraphViz on Ubuntu:

1
sudo apt-get install GraphViz

Installed GraphViz for Python:

1
pip install GraphViz.

#have a look at the model

1
2
python python/draw_net.py models/bvlc_reference_caffenet/deploy.prototxt caffenet.png
open caffenet.png


本作品采用知识共享署名 2.5 中国大陆许可协议进行许可,欢迎转载,但转载请注明来自 Sunshine 并保持转载后文章内容的完整。本人保留所有版权相关权利。

本文链接:http://gaobb.github.io/2016/02/24/Caffe 使用总结/

坚持原创技术分享,您的支持将鼓励我继续创作!

热评文章